package cn.edu.jssvc.skills.correcting_4;

import android.support.v4.text.TextUtilsCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.Toast;

public class Main4Activity extends AppCompatActivity {
 private  EditText phoneedit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
         phoneedit=findViewById(R.id.phone_edit);
        phoneedit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(11){}});
        phoneedit.setImeOptions(EditorInfo.IME_ACTION_DONE);
        if (!isphone(phoneedit.getText().toString())){

            Toast.makeText(Main4Activity.this,"电话格式不正确",Toast.LENGTH_LONG).show();

        }else {
            Toast.makeText(Main4Activity.this, "格式正确", Toast.LENGTH_SHORT).show();
        }
        }
        public boolean isphone(String phone){
            String tel = "^((1[3,5,7,8][0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
            if (TextUtils.isEmpty(phone)) {
                return false;
            } else {
                return phone.matches(tel);
            }



        }

}